package com.csg.web.amqp;

import com.csg.web.config.RabbitConfig;
import com.csg.web.support.DeferredResultHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.async.DeferredResult;

/**
 * 消息接收者
 *
 * @author george
 */
@Slf4j
@Component
@RabbitListener(queues = RabbitConfig.QUEUE_NAME_1)
public class Receiver {

    /**
     * 消息接收方法
     *
     * @param message 接收到的消息
     */
    @RabbitHandler
    public void process(String message) {
        log.info("Receiver: " + message);
        DeferredResult deferredResult = DeferredResultHolder.get(message);
        DeferredResultHolder.remove(message);
        deferredResult.setResult("success");
    }
}
